// pages/main-video/main-video.js
import { getTopMv } from "../../serive/video"
 
Page({
  data:{
    videoList:[],
    offset:0,
    hasMore:true
  },
  onLoad() {
    this.fetchTopMv()
  },
  async fetchTopMv() {
    // getTopMv().then(res => {
    //   this.setData({ videoList: res.data })
    // })
    const res = await getTopMv(10,this.data.offset)
    this.data.hasMore = res.hasMore
    // 将请求的新数据追加进新数组中
    const newList = [...this.data.videoList,...res.data]
    this.setData({ videoList: newList })
   
    this.setData({ offset: this.data.videoList.length })
  },
  onReachBottom() {
    if (!this.data.hasMore) return
    this.fetchTopMv()
  },
  async onPullDownRefresh() {
    // 初始化状态
    this.setData({ videoList:[] })
    this.data.offset = 0
    this.data.hasMore = true

    // 结束下拉请求
    await this.fetchTopMv()
    wx.stopPullDownRefresh()
  },
  onVideoItemTap(event) {
      const item = event.currentTarget.dataset.item;
      wx.navigateTo({
        url: `/packageDetailVideo/pages/detail-video/detail-video?id=${item.id}`,
      })
  }
})